import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SPetExploreResult } from "../../../../../Message/Public/SPetExploreResult";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ClockManager } from "../../../manager/ClockManager";
import { BaseItem } from "../../common/BaseItem";
import { SReward } from "../../../../../Message/Public/SReward";
import { ItemData } from "../../../resource/info/ItemData";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SecTimerView } from "../../common/SecTimerView";
import { PetExploreConfigInfo } from "../../../resource/info/PetExploreConfigInfo";
import { SPetExploreInfo } from "../../../../../Message/Public/SPetExploreInfo";
//class PetExploreAutoResultRenderer
    
    export  class PetExploreAutoResultRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._baseItemArray = [];
            this.init();
            return;
        }

        public set isInExplore(arg1: Boolean)
        {
            this._isInExplore = arg1;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            super.data = arg1;
            this._exploreResult = arg1 as SPetExploreResult;
            if (this._exploreResult) 
            {
                this._exploreConfigInfo = PetExploreConfig.instance.getExploreConfigByLevel(this._exploreResult.currentLevel);
                if (this._exploreConfigInfo) 
                {
                    this._levelTxt.text = Language.getStringByParam(54637, this._exploreConfigInfo.level);
                    this._nameTxt.text = this._exploreConfigInfo.name;
                    this._petExploreInfo = Cache.instance.petExplore.petExploreInfo;
                    this._isInExplore = this._petExploreInfo.isInExplore && this._petExploreInfo.currentLevel == this._exploreConfigInfo.level;
                    if (this._isInExplore) 
                    {
                        this._timeTxt.setLeftTime((this._petExploreInfo.exploreEndDt.time - ClockManager.instance.nowDate.time) / 1000);
                        this._statusTxt.htmlText = Language.getString(54638);
                        this._rewardSprite.visible = false;
                        this._tipSprite.visible = true;
                    }
                    else 
                    {
                        this._statusTxt.htmlText = Language.getString(54639);
                        this._rewardSprite.visible = true;
                        this._tipSprite.visible = false;
                    }
                }
                loc1 = this._exploreResult.rewards;
                loc5 = 0;
                while (loc5 < this._baseItemArray.length) 
                {
                    loc2 = this._baseItemArray[loc5] as BaseItem;
                    if (loc3 = loc1[loc5] as SReward) 
                    {
                        (loc4 = new ItemData(loc3.code)).itemAmount = loc3.num;
                        loc2.itemData = loc4;
                    }
                    else 
                    {
                        loc2.itemData = null;
                    }
                    ++loc5;
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            this._bg = ObjCreate.createBg(0, 0, 300, 20, this, ImagesConst.Friend_over);
            this._levelTxt = ObjCreate.createTextField("", 10, 3, 100, 20, this, GlobalStyle.textFormatOrange);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt = ObjCreate.createTextField("", 90, 3, 100, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._statusTxt = ObjCreate.createTextField("", 200, 3, 100, 20, this);
            this._statusTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._rewardSprite = new Object /* flash.display.Sprite */();
            this._rewardSprite.x = 10;
            this._rewardSprite.y = 27;
            this.addChild(this._rewardSprite);
            ObjCreate.createTextField(Language.getString(54640), 0, 0, 100, 20, this._rewardSprite, GlobalStyle.textFormatGreen);
            var loc2=0;
            while (loc2 < 3) 
            {
                ObjCreate.createBg(loc2 * 41, 20, 38, 38, this._rewardSprite, ImagesConst.PackItemBg);
                loc1 = new BaseItem();
                loc1.isDragAble = false;
                loc1.isDropAble = false;
                loc1.setSize(32, 32);
                loc1.x = 2 + loc2 * 41;
                loc1.y = 22;
                loc1.itemData = new ItemData(11100122);
                this._rewardSprite.addChild(loc1);
                this._baseItemArray.push(loc1);
                ++loc2;
            }
            this._tipSprite = new Object /* flash.display.Sprite */();
            this._tipSprite.x = 10;
            this._tipSprite.y = 27;
            this.addChild(this._tipSprite);
            this._timeTxt = new SecTimerView();
            this._timeTxt.setParse("mm: ss");
            this._timeTxt.mouseEnabled = false;
            this._timeTxt.width = 175;
            this._timeTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeTxt.defaultTextFormat = GlobalStyle.textFormatRed;
            this._tipSprite.addChild(this._timeTxt);
            ObjCreate.createTextField(Language.getString(54641), 35, 0, 100, 20, this._tipSprite, GlobalStyle.textFormatRed);
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_statusTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tipSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_timeTxt: SecTimerView;

        /* internal */ /* var */_baseItemArray: Array<any>;

        /* internal */ /* var */_exploreResult: SPetExploreResult;

        /* internal */ /* var */_exploreConfigInfo: PetExploreConfigInfo;

        /* internal */ /* var */_petExploreInfo: SPetExploreInfo;

        /* internal */ /* var */_isInExplore: Boolean;
    }
